package com.ismiao.ServletJSP;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * Servlet implementation class HttpPost
 */
@WebServlet("/HttpPost")
public class HttpPost extends HttpServlet {
	private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HttpPost() {
        super();
        System.out.println("HttpServlet#HttpServlet()");
    }
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out = response.getWriter();
		//生成HTML
		out.println("<html>");
		out.println("<head>");
		out.println("<title>用户注册数据</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("<h1>用户注册数据</h1>");
		out.println("<br/><hr/><br/>");
		out.println("<ul>");
		//字符集
		request.setCharacterEncoding("UTF-8");
		//从表单中获得数据
		out.println("  <li>用户名称: " + request.getParameter("username"));
		out.println("  <li>输入密码: " + request.getParameter("password"));
		out.println("  <li>确认密码: " + request.getParameter("confpass"));
		//获取复选框的表单选项
		String interests[] = request.getParameterValues("interests");
		out.println("  <li>兴趣爱好: <br/>");
		if (interests != null) {
			for (int i = 0; i < interests.length; i++) {
				out.println(interests[i] + "<br/>");
			}
		}
		out.println("</ul>");
		out.println("</body>");
		out.println("</html>");
	}   	  	    
}